Filename extension | .stl |
---|---|
Developed by | 3D Systems |
Type of format | Stereolithography |
STL is a file format native to the stereolithography CAD software created by 3D Systems. This file format is supported by many other software packages; it is widely used for rapid prototyping and computer-aided manufacturing. STL files describe only the surface geometry of a three dimensional object without any representation of color, texture or other common CAD model attributes. The STL format specifies both ASCII and binary representations. Binary files are more common, since they are more compact [1]. In 2011, ASTM replaced the STL format with the Additive Manufacturing File Format (AMF), which has native support for color, multiple materials, and constellations.
An STL file describes a raw unstructured triangulated surface by the unit normal and vertices (ordered by the right-hand rule) of the triangles using a three-dimensional Cartesian coordinate system.
Contents |
An ASCII STL file begins with the line:
solid name
where name is an optional string (though if name is omitted there must still be a space after solid). The file continues with any number of triangles, each represented as follows:
facet normal ni nj nk outer loop vertex v1x v1y v1z vertex v2x v2y v2z vertex v3x v3y v3z endloop endfacet
where each n or v is a floating point number in sign-mantissa 'e'-sign-exponent format, e.g., "-2.648000e-002". The file concludes with:
endsolid name
The structure of the format suggests that other possibilities exist (e.g., facets with more than one 'loop', or loops with more than three vertices) but in practice, all facets are simple triangles.
White space (spaces, tabs, newlines) may be used anywhere in the file except within numbers or words. The spaces between 'facet' and 'normal' and between 'outer' and 'loop' are required.[1]
Because ASCII STL files can become very large, a binary version of STL exists. A binary STL file has an 80 character header (which is generally ignored – but which should never begin with 'solid' because that will lead most software to assume that this is an ASCII STL file). Following the header is a 4 byte unsigned integer indicating the number of triangular facets in the file. Following that is data describing each triangle in turn. The file simply ends after the last triangle.
Each triangle is described by twelve 32-bit-floating point numbers: three for the normal and then three for the X/Y/Z coordinate of each vertex – just as with the ASCII version of STL. After the twelve floats there is a two byte unsigned 'short' integer that is the 'attribute byte count' – in the standard format, this should be zero because most software does not understand anything else.[1]
Floating point numbers are represented as IEEE floating point numbers and the endianness is assumed to be little endian although this is not stated in documentation.
UINT8[80] – Header UINT32 – Number of triangles
foreach triangle REAL32[3] – Normal vector REAL32[3] – Vertex 1 REAL32[3] – Vertex 2 REAL32[3] – Vertex 3 UINT16 – Attribute byte count end
There are at least two variations on the binary STL format for adding colour information:
The red/green/blue ordering within those two bytes is reversed in these two approaches – so whilst these formats could easily have been compatible the reversal of the order of the colours means that they are not – and worse still, a generic STL file reader cannot automatically distinguish between them. There is also no way to have facets be selectively transparent because there is no per-facet alpha value – although in the context of current rapid prototyping machinery, this is not important.
In both ASCII and binary versions of STL, the facet normal should be a unit vector pointing outwards from the solid object. In most software this may be set to (0,0,0) and the software will automatically calculate a normal based on the order of the triangle vertices using the 'right-hand rule'. Some STL loaders (e.g. the STL plugin for Art of Illusion) check that the normal in the file agrees with the normal they calculate using the right-hand rule and warn you when it does not. Other software may ignore the facet normal entirely and use only the right-hand rule. Although it is rare to specify a normal that cannot be calculated using the right-hand rule, in order to be entirely portable, a file should both provide the facet normal and order the vertices appropriately. A notable exception is SolidWorks which uses the normal for shading effects.
Stereolithography machines are basically 3D printers that can build any volume shape as a series of slices. Ultimately these machines require a series of closed 2D contours that are filled in with solidified material as the layers are fused together.
The natural file format for such a machine would be a series of closed polygons corresponding to different Z-values. However, since it's possible to vary the layer thicknesses for a faster though less precise build, it seemed easier to define the model to be built as a closed polyhedron that could be sliced at the necessary horizontal levels.
The STL file format appears capable of defining a polyhedron with any polygonal facet, but in practice it's only ever used for triangles, which means that much of the syntax of the ASCII protocol is superfluous.
STL files are supposed to be closed and connected like a combinatorial surface, where every edge is part of exactly two triangles, and not self-intersecting. Since the syntax does not enforce this property, it can be ignored for applications where the closedness doesn't matter.
The closedness only matters insofar as the software which slices the triangles requires it to ensure that the resulting 2D polygons are closed. Sometimes such software can be written to clean up small discrepancies by moving endpoints of edges that are close together so that they coincide. The results are not predictable, but it is often sufficient to get the job done.
Many computer-aided design systems are able to output the STL file format among their other formats because it's quick and easy to implement, if you ignore the connection criteria of the triangles. Many computer-aided manufacturing systems require triangulated models as the basis of their calculation.
Since an STL file output, of a sorts, is almost always available from the CAD system, it's often used as a quick method for importing the necessary triangulated geometry into the CAM system.
It can also be used for interchanging data between CAD/CAM systems and computational environments such as Mathematica.
Once it works, there is very little motivation to change, even though it is far from the most memory and computationally efficient method for transferring this data. Many integrated CAD and CAM systems transfer their geometric data using this accidental file format, because it's impossible to go wrong.
There are many other file formats capable of encoding triangles available, such as VRML, DXF, but they have the disadvantage that it's possible to put things other than triangles into it, and thus produce something ambiguous or unusable.